package directory_sync;

import java.io.File;
import java.io.IOException;
import java.util.List;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;

public class TestSyncRunner
{
	private static Logger logger = Logger.getLogger("syslog");
	private static List<File> sourceList;
	private static List<File> targetList;
	
	public static void main(String[] args) throws IOException
	{
		logger.setLevel(Level.DEBUG);
		
		String sourcePath = "C:/GradedExercise1/source1";
		String targetPath = "C:/GradedExercise1/target";
		new SyncRunner(sourcePath, targetPath, logger);

		SyncReader readSourceDir = new SyncReader(sourcePath);
		sourceList = readSourceDir.getFileList();
		SyncReader readTargetDir = new SyncReader(targetPath);
		targetList = readTargetDir.getFileList();
		System.out.println("checking " + sourceList.size() + " files");
		for(int i = 0; i < sourceList.size(); i++)
		{
			File sourcefile = new File(sourceList.get(i).getAbsolutePath());
			File targetfile = new File(targetList.get(i).getAbsolutePath());
			
			if(sourceList.get(i).isFile())
			{
				boolean same = equals(sourcefile, targetfile);
				
				if(!same)
				{
					System.out.println("Error: different name at position " + i);
				}
			}
		}
		
		System.out.println("check done");
		System.exit(0);
	}
	
	public static boolean equals(File file1, File file2)
	{
		if(file1.length() == file2.length())
		{
			String filename1 = file1.getName().toString();
			String filename2 = file2.getName().toString();
	        //compare the strings
	        int result = filename1.compareTo(filename2);
	        if(result == 0)
	        {
		        return true;
	        }
	        else
	        {
	        	return false;
	        }
		}
		else
		{
			return false;
		}
	}
}